import BaseModel from './baseModel'
import { get } from '../ajax/axios'
import { Api } from '../ajax/api'
import { ImageMfit } from '../utils/filters'
import '../../node_modules/highlight.js/styles/xcode.css'
import TimeStamp from 'time-stamp'

class ProductModel extends BaseModel {

  cover: string = ''
  name: string = ''
  startDate:string = ''
  endDate:string = ''
  describe: string = ''
  content: string = ''

  get dateStr() {
    if (!this.startDate || !this.endDate) return ''
    const start = TimeStamp('YYYY/MM/DD', new Date(this.startDate))
    const end = TimeStamp('YYYY/MM/DD', new Date(this.endDate))
    return `${start} - ${end}`
  }

  get pcMeIconUrl() {
    return ImageMfit(this.cover, 150, 150)
  }

  get pcListIconUrl() {
    return ImageMfit(this.cover, 100, 100)
  }

  static async getMeModels() {
    const json = await get(Api.product.me) as any
    return this.modelsWithArr(json)
  }

  static async getModels(data: {}) {
    const json = await get(Api.product.list, data) as any
    return {
      list: this.modelsWithArr(json.list),
      total: json.total
    }
  }

  static getTypes() {
    return get(Api.product.types)
  }

  static async getDetail(id: string) {
    const json = await get(`${Api.product.detail}${id}`) as any
    const model = new this()
    model.setDataWithJson(json)
    return model
  }
}

export default ProductModel
